from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784',data_home='MLPractice\dataset',parser='auto')
X = mnist['data'].values
y = mnist['target'].values
print(X.shape)
print(y.shape)
X_train,X_test,y_train,y_test = X[:60000],X[60000:],y[:60000],y[60000:]

import numpy as np
shuffle_index = np.random.permutation(X_train.shape[0])
print(shuffle_index)
X_train,y_train = X_train[shuffle_index],y_train[shuffle_index]

y_train_7 = (y_train=='7')
y_test_7 = (y_test=='7')

from sklearn.linear_model import SGDClassifier
classifier = SGDClassifier(max_iter=10)
classifier.fit(X_train,y_train_7)

from sklearn.model_selection import cross_val_score
cross_result = cross_val_score(classifier,X_train,y_train_7,cv=6,scoring='accuracy')
print(cross_result.shape)
from sklearn.model_selection import cross_val_predict
cross_predict_result = cross_val_predict(classifier,X_train,y_train_7,cv=6)
print(cross_predict_result.shape)
from sklearn.metrics import confusion_matrix
cm_result = confusion_matrix(y_train_7,cross_predict_result)
print(cm_result)

y_scores = classifier.decision_function(X_train)
print(y_scores)

from sklearn.metrics import precision_recall_curve
(precisions,recalls,threshold) = precision_recall_curve(y_train_7,y_scores)
print(precisions.shape)
print(recalls.shape)
print(threshold.shape)

